package com.wine.exam.domain;


import com.baomidou.mybatisplus.annotation.*;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.wine.common.annotation.Excel;

import lombok.*;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.Range;


import javax.validation.constraints.*;
import java.io.Serializable;
import java.util.Date;

/**
 * 题目对象 exam_question
 *
 * @author wine
 * @date 2022-09-02
 */
@Getter
@Setter
@EqualsAndHashCode
@AllArgsConstructor
@NoArgsConstructor
@ToString
@TableName("exam_question")

public class Question  implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 关联查询所需
     */
    @TableField(exist = false)
    private Subject subject;

    /**
     * 题目主键
     */
    @JsonSerialize(using = ToStringSerializer.class)
    @TableId(value = "question_id", type = IdType.AUTO)
    private Long questionId;


    /**
     * 标题
     */
    @NotBlank(message = "题目标题不能为空")
    @Length(min = 1, max = 100, message = "题目标题长度在{min}到{max}个之间")
    @Excel(name = "题目标题")
    @TableField(value = "question_title")
    private String questionTitle;

    /**
     * 排序
     */
    @TableField(value = "order_num")
    @Excel(name = "排序")
    private Long orderNum;

    /**
     * 1单选2：多选3：判断4：填空5：简答
     */
    @Excel(name = "问题类型： 1单选2：多选3：判断4：填空5：简答")
//    @Range(min = 0, max = 1, message = "类型只能是：1单选2：多选3：判断4：填空5：简答")
    @Pattern(regexp = "[1,2,3,4,5]", message = "类型只能是:1:单选,2:多选,3:判断,4:填空5:简答")
    @TableField(value = "question_type")
    private String questionType;

    /**
     * 学科
     */
    @Excel(name = "学科id")
    @TableField(value = "subject_id")
    @JsonSerialize(using = ToStringSerializer.class)
    private Long subjectId;

    /**
     * 题目总分：千分制  :  TODO   @JsonSerialize(using = ToStringSerializer.class) 是否json以及是否千分之
     */
    @Excel(name = "题目总分：千分制")
//    暂定百分制，且是整形，不存在小数
    @TableField(value = "question_score")
    @Max(value = 100, message = "分数不能大于{max}")
    @Min(value = 1, message = "分数不能低于{min}")
    private Long questionScore;

    /**
     * 选项
     */
    @Excel(name = "选项")
    @TableField(value = "question_items")
//TODO 单选多选判断必须要有正确答案，但是填空这些可以没有 - - 待处理
    private String questionItems;

    /**
     * 题目难度
     */
    @Excel(name = "题目难度:1:简单,2:一般,3:困难" ,readConverterExp ="1:简单,2:一般,3:困难" )
    @TableField(value = "difficult")
//    @Range(min = 1, max = 3, message = "题目难度可选项目：1=简单2=一般3=困难")
    @Pattern(regexp = "[1,2,3,4,5]", message = "题目难度可选项目:1:简单,2:一般,3:困难")
    private String difficult;

    /**
     * 正确答案：有简答，所以为text好些
     */
    @NotBlank(message = "正确答案不能为空")
    @Length(min = 1, max = 100, message = "正确答案长度再{min}到{max}个之间")
    @Excel(name = "正确答案")
    @TableField(value = "correct")
    private String correct;

    /**
     * 题目解析
     */
    @Excel(name = "解析")
//    @NotBlank(message = "解析答案不能为空")
    @Length(max = 200, message = "解析答案长度不能超过{max}个字符")
    @TableField(value = "info")
    private String info;


    /**
     * 问题状态（0正常 1停用）
     * 添加时，默认为0 校验只为修改
     */
    @TableField(value = "status")
    @Excel(name = "问题状态：0:正常,1:停用", readConverterExp = "0:正常,1:停用")
    @Pattern(regexp = "[0,1]", message = "问题状态:0=正常,1=停用")
    private String status;

    /**
     * 删除标志（0代表存在 2代表删除）
     */
    @TableLogic
    @TableField(value = "del_flag", select = false)
    private String delFlag;

    /**
     * 创建人
     */

    @TableField(value = "create_by")
    private String createBy;

    /**
     * 创建时间
     */

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "create_time", fill = FieldFill.INSERT)
    private Date createTime;


    /**
     * 更新人
     */

    @TableField(value = "update_by")
    private String updateBy;

    /**
     * 更新时间
     */
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @TableField(value = "update_time", fill = FieldFill.INSERT_UPDATE)
    private Date updateTime;

}
